package xyz.prob.kun.common.model;


import lombok.Getter;
import xyz.prob.kun.common.enums.HttpStatusEnum;

@Getter
public class AjaxResult<T>  {

    private final int code;

    private final String msg;

    private final T data;


    public AjaxResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static AjaxResult<Void> createOf(HttpStatusEnum httpStatusEnum) {

        return new AjaxResult<Void>(httpStatusEnum.getCode(),httpStatusEnum.getDesc(),null);
    }

    public  static <J> AjaxResult<J> error(String message, J obj) {

        return new AjaxResult<J>(HttpStatusEnum.ERROR.getCode(),message,obj);
    }

    public  static <J> AjaxResult<J> error(J obj) {

        return new AjaxResult<J>(HttpStatusEnum.ERROR.getCode(),HttpStatusEnum.ERROR.getDesc(),obj);
    }
    public  static  AjaxResult<Void> error(String message) {

        return new AjaxResult<>(HttpStatusEnum.ERROR.getCode(),message,null);
    }


    public  static <J> AjaxResult<J> success(String message, J obj) {

        return new AjaxResult<J>(HttpStatusEnum.SUCCESS.getCode(),message,obj);
    }

    public  static  AjaxResult<Void> success(String message) {

        return new AjaxResult<>(HttpStatusEnum.SUCCESS.getCode(),message,null);
    }

    public  static <J> AjaxResult<J> success(J obj) {

        return new AjaxResult<J>(HttpStatusEnum.SUCCESS.getCode(),HttpStatusEnum.SUCCESS.getDesc(),obj);
    }

}
